<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>选择房屋</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">选择房屋</h1>
		</header>
		<div class="mui-content">
			<div class="search-li">
		    	<div class="search-box">
				    <input type="search" id="house_serch_input" placeholder="请输入房屋名称">
					<button type="button" id="serchHouse">查询</button>
		    	</div>
			</div>
			<div class="houst-list">
				<ul id="houseUl">
					
				</ul>
			</div>
		</div>
		<script src="../js/jquery.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/md5.js"></script>
		<script>
			
			function initPage_building(q_word,o_cond){
				var q_word = q_word;
				var o_cond = o_cond;
				var mobile = localStorage.getItem('mobile');//本地取到电话号码
				var timestamp = formatDateTime();//年月日时分秒
				var key = 'udacs!@#';//固定的key值
				var token = mobile + timestamp + key;//token的拼接
				var md5 = hex_md5(token);//token的ma5加密
				//获取楼栋list
				$.ajax(httpUrl+'get_house_list',{
					data:JSON.stringify({
						"auth":{
							"mobile":mobile,
							"token":md5,
							"imei":"imei",
							"imsi":"imsi",
							"timestamp" :timestamp
						},
				   		"api_ver":"1",
						"req":{
							"mobile":mobile ,
							"q_word":q_word ,
							"o_cond":o_cond,
							"page":"1",
							"type":"1"
						}
					}),
					dataType:'json',//服务器返回json格式数据
					type:'post',//HTTP请求类型
					timeout:10000,//超时时间设置为10秒；
					contentType: "text/plain; charset=utf-8",					
					success:function(data){
						var resp =JSON.stringify(data.resp)
						var res = JSON.parse(resp);
						var houseList = document.getElementById('houseUl');
						houseList.innerHTML = '';//清空数据
						mui.each(res,function(ind,item) {
							houseList.insertAdjacentHTML('beforeEnd','<li class="houseLi"  data-houseId="'+item.id+'" data-houseName="'+item.name+'"><span class="icon-house"></span><span class="house-name">'+item.name+'</span></li>');
						});
					},
					error:function(xhr,type,errorThrown){
						mui.toast('网络异常或者服务器出错：'+type,{duration:'2000',type:''});
					}
						
				})
			}
			initPage_building('','');
			//模糊查询
			document.getElementById("serchHouse").addEventListener('tap',function(){
				var q_word = document.getElementById("house_serch_input").value;
				initPage_building(q_word,'');
			})
			//选择房屋调到人员页面
			mui("#houseUl").on('tap','li',function(){
				var houseId = this.getAttribute('data-houseId');
				var houseName = this.getAttribute('data-houseName');
				location.href = 'person.html?houseId='+houseId;
			})
		</script>
	</body>

</html>